*LOAD CLEANED SI WITH FIRM-SPECIFIC PRODUCTIVITY BINS
clear
use "${mastersi}si_analysis_combined0112.dta"

set matsize 5000

gen prod2 = floor(prod3/10)

*using 1991 firm pdty bins
collapse (sum) value_added (mean) t2mCDD t2mmean yrpre yrrh2m, by(prod2 kabu year Bin3ter)
tab Bin3ter, gen(BinPdty)


forvalues i = 1(1)3{
gen Bin`i't2mmean = BinPdty`i'*t2mmean
}


forvalues i = 1(1)3{
gen Bin`i'yrpre = BinPdty`i'*yrpre
}


forvalues i = 1(1)3{
gen Bin`i'yrrh2m = BinPdty`i'*yrrh2m
}

gen lvlad = ln(value_added)


*Create newid
egen newid = group(kabu prod2 Bin3ter)
drop if newid==.


*Generate product*year fixed effects

egen yearXprod2= group(year prod2)
sort year prod2
order year prod2 yearXprod2

*Generate year*island fixed effects
gen prv = floor(kabu/100)

gen island = .
replace island = 1 if prv<30
replace island = 2 if prv>=30 & prv<60
replace island = 3 if prv>=60 & prv<70
replace island = 4 if prv>=70

egen yearXis= group(year island)


*Table 3
eststo clear

eststo lvlad1: reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 i.Bin3ter#c.year newid) vce(cluster newid)
estadd local YearIndustryFE "Yes"
estadd local YearIslandFE ""
estadd local Clustering "bin*kabu*year"
estadd local KabuBinProd2FE "Yes"

eststo lvlad2: reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXis i.Bin3ter#c.year newid) vce(cluster newid)
estadd local YearIndustryFE ""
estadd local YearIslandFE "Yes"
estadd local Clustering "bin*kabu*year"
estadd local KabuBinProd2FE "Yes"

eststo lvlad3: reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXis yearXprod2 i.Bin3ter#c.year newid) vce(cluster newid)
estadd local YearIndustryFE "Yes"
estadd local YearIslandFE "Yes"
estadd local BinTime "Yes"
estadd local Clustering "bin*kabu*year"
estadd local KabuBinProd2FE "Yes"

esttab lvlad1 lvlad2 lvlad3, starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label mlabel(exit exit exit) dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "KabuBinProd2FE" "Clustering") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")

esttab lvlad1 lvlad2 lvlad3 using "${tables}table3.tex",, starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label mlabel(exit exit exit) dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "KabuBinProd2FE" "Clustering") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")



*Table 7
keep if prod2 >=35

eststo clear

eststo lvlad1: reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 i.Bin3ter#c.year newid) vce(cluster newid)
estadd local YearIndustryFE "Yes"
estadd local YearIslandFE ""
estadd local Clustering "bin*kabu*year"
estadd local KabuBinProd2FE "Yes"

eststo lvlad2: reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXis i.Bin3ter#c.year newid) vce(cluster newid)
estadd local YearIndustryFE ""
estadd local YearIslandFE "Yes"
estadd local Clustering "bin*kabu*year"
estadd local KabuBinProd2FE "Yes"


eststo lvlad3: reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXis yearXprod2 i.Bin3ter#c.year newid) vce(cluster newid)
estadd local YearIndustryFE "Yes"
estadd local YearIslandFE "Yes"
estadd local BinTime "Yes"
estadd local Clustering "bin*kabu*year"
estadd local KabuBinProd2FE "Yes"


esttab lvlad1 lvlad2 lvlad3, starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label mlabel(exit exit exit) dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "KabuBinProd2FE" "Clustering") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")

esttab lvlad1 lvlad2 lvlad3 using "${tables}table7.tex",, starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label mlabel(exit exit exit) dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "KabuBinProd2FE" "Clustering") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")






